package com.motionlog.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

import com.motionlog.R;
import com.motionlog.model.Database;
import com.motionlog.model.Saying;

public class Welcome extends Activity {

	Handler handler = new Handler();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);

		Saying saying = Database.getInstance(this).getRandomSaying();

		TextView content = (TextView) findViewById(R.id.content);
		content.setText(String.format("%s（%s）", saying.content, saying.author));

		SharedPreferences sets = getSharedPreferences("settings", MODE_PRIVATE);
		final boolean firstUse = sets.getBoolean("first-use", true);
		
		sets.edit().putBoolean("first-user", false).commit();
	
		boolean hasPassword = sets.getBoolean("password", false);
		
		// hasPassword = true;
		final Class startActivity;
		if (hasPassword) {
			startActivity = Password.class;
		} else {
			/*
			boolean hasTutor = sets.getBoolean("tutor", true);
			if (hasTutor) {
				startActivity = Tutorial.class;
				sets.edit().putBoolean("tutor", false).commit();
			} else {
				startActivity = Home.class;
			}
			*/
			//此处为设置密码
			startActivity = SettingPassword.class;
		}
		
		handler.postDelayed(new Runnable() {
			@Override
			public void run() {
				Intent i = new Intent(Welcome.this, startActivity);
				if (firstUse) {
					i.putExtra("action", "set");
				}
				startActivity(i);
				finish();
			}
		}, 3000);
	}
}
